<?php


namespace app\admin\model;

use think\model\Relation;

class ToursOrder extends Relation {

        protected $link = [
            'tours' => [
                'mapping_type' => BELONGS_TO,
                'class_name' => 'Tours',
                'foreign_key' => 'tours_id',
                'mapping_fields' => 'title as tours_title',
                'as_fields' => 'tours_title',
                'parent_key' => 'id'
            ],
            'supplier' => [
                'mapping_type' => BELONGS_TO,
                'class_name' => 'Supplier',
                'foreign_key' => 'supplier_id',
                'mapping_fields' => 'name as supplier_name',
                'as_fields' => 'supplier_name',
                'parent_key' => 'id'
            ],
            'user' => [
                'mapping_type' => BELONGS_TO,
                'class_name' => 'User',
                'foreign_key' => 'uid',
                'mapping_fields' => 'email,mobile,login_ip,username',
                'as_fields' => 'email,mobile,login_ip,username',
                'parent_key' => 'id'
            ],
            'userinfo' => [
                'mapping_type' => BELONGS_TO,
                'class_name' => 'UserInfo',
                'foreign_key' => 'uid',
                'mapping_fields' => 'realname as realname',
                'as_fields' => 'realname',
                'parent_key' => 'user_id'
            ],
            'member' => [
                'mapping_type' => BELONGS_TO,
                'class_name' => 'Member',
                'foreign_key' => 'mid',
                'mapping_fields' => 'realname as member_name',
                'as_fields' => 'member_name',
                'parent_key' => 'id'
            ],
        ];

        protected function _after_select(&$resultSet, $options = array()) {
                parent::_after_select($resultSet, $options);
                foreach ($resultSet as $key => $value) {
                        $resultSet[$key]['tours_url'] = U("/xianlu/" . $value['tours_id'], '', 'html', 'www');
                        $resultSet[$key]['order_payment'] = M("ToursPayment")->where(array('order_id' => $value['order_id']))->getField("payment");	
                }
        }

        protected function _after_find(&$result, $options = array()) {
                parent::_after_find($result, $options);
                $result['tours_url'] = U("/xianlu/" . $result['tours_id'], '', 'html', 'www');
        }

}
